package com.hxkcloud.patient.fragments;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;

import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.hyphenate.easeui.EaseConstant;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.recyclebanner.InitRecycleViewpager;
import com.hxkcloud.patient.R;
import com.hxkcloud.patient.YjhApplication;
import com.hxkcloud.patient.activitys.ArticleDetailActivity;
import com.hxkcloud.patient.activitys.ChatFragmentActivity;
import com.hxkcloud.patient.activitys.JoinDepartmentActivity;
import com.hxkcloud.patient.activitys.MessageMainActivity;
import com.hxkcloud.patient.activitys.NewNewsActivity;
import com.hxkcloud.patient.activitys.QRcodeScanActivity;
import com.hxkcloud.patient.activitys.WebActivity;
import com.hxkcloud.patient.adapter.InformationAdapter;
import com.hxkcloud.patient.aerotel.AerotelActivity;
import com.hxkcloud.patient.beans.ArticleBean;
import com.hxkcloud.patient.beans.ArticleWholeBean;
import com.hxkcloud.patient.beans.BannerBean;
import com.hxkcloud.patient.beans.BannerWholeBean;
import com.hxkcloud.patient.beans.DepartmentIndexInfo;
import com.hxkcloud.patient.beans.NurseBean;
import com.hxkcloud.patient.beans.NurseWholeBean;
import com.hxkcloud.patient.dborm.LoginInfoDao;
import com.hxkcloud.patient.request.MessageCode;
import com.hxkcloud.patient.request.YiJiaHuNetWorkUtils;
import com.hxkcloud.patient.utils.BrightnessUtils;
import com.hxkcloud.patient.utils.ImageOptionUtils;
import com.hxkcloud.patient.utils.StringUtil;
import com.hxkcloud.patient.views.CircleImageView;
import com.hxkcloud.patient.views.CustomSwipeToRefresh;
import com.hxkcloud.patient.views.LinearListView;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户端首页
 * Created by Administrator on 2016/12/26.
 */

public class UserHomePageFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener, LinearListView.OnItemClickListener {
    private View view;
    private LinearLayout ll_empty;//没有科室数据时显示，头部可以扫描二维码
    private LinearLayout ll_ttitle;
    private ImageView iv_qrcode;
    private TextView tv_title;
    private ImageView iv_tmessage;
    private TextView nodepartmentTV;
    private CustomSwipeToRefresh swipeRefreshLayout;
    private InitRecycleViewpager recycleViewpager;
    private List<BannerBean> imgelist;
    private LinearLayout line_yuan_qian, line_yuan_zhong, line_yuan_hou, line_sui_fang;
    private LinearLayout ll_course, ll_news;

    private CircleImageView responsibility_nurse_icon;
    private TextView responsibility_nurse_name, nurse_work_office, nurse_work_time;
    private LinearListView information_listView;
    private InformationAdapter informationAdapter;
    private List<ArticleBean> newsInfoList;
    // private ScrollView scroll_view;
    //责任护士不为空就显示出来
    private LinearLayout line_nurse_empty;
    //咨询按钮
    private TextView text_advisory;
    //责任护士为空的时候显示出来
    private TextView responsibility_nurse_empty;
    private LoginInfoDao loginInfoDao;
    private String departmentId = "";
    private int pageIndex = 1;
    private int pageSize = 15;
    private ArrayList<NurseBean> nurses;
    private final int REQUEST_QRCODE = 500;
    private final int REQUEST_JOIN = 501;
    private DepartmentIndexInfo departmentInfo;


    //退出科室
    private PopupWindow popup_easynotice;
    private TextView tv_easynotice_title;
    private TextView tv_openEcg;
    private LinearLayout ll_ecg;
    private TextView tv_easynotice_cancel;
    private TextView tv_easynotice_sure;
    private ArticleWholeBean resultBean;
    private ImageView image_banner_empty;
    private ImageView iv_message;
    private TextView msg_number;
    private ImageView iv_msgpoint;
    private boolean showIcon;

    public UserHomePageFragment() {
        super();
    }

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {
            case MessageCode.NETWORKCODE_GETDEPARTMENTINDEXINFO_SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                if (msg.obj != null) {
                    departmentInfo = (DepartmentIndexInfo) msg.obj;
                    return;
                } else {
                    //    toastMsg(R.string.departmentinfogetfail);
                }

                break;
            case MessageCode.NETWORKCODE_GETDEPARTMENTINDEXINFO_FAILURE:
                swipeRefreshLayout.setRefreshing(false);
                if (msg.obj != null) {
                    //  toastMsg((String) msg.obj);
                } else {
                    //  toastMsg(R.string.departmentinfogetfail);
                }

                break;
            case MessageCode.NETWORKCODE_DEPARTMENTLEFT_SUCCESS:
                //Log.e("首页2", departmentInfo.toString());
                toastMsg((String) msg.obj);
                ll_empty.setVisibility(View.VISIBLE);
                // ll_info.setVisibility(View.GONE);

                loginInfo.setDepartmentId("");
                loginInfoDao.setUser(loginInfo);

                YjhApplication.msg_monitor = false;//监测提醒（医护）
                YjhApplication.msg_assessNurse = false;//评估提醒（医护）
                YjhApplication.msg_assessPatient = false;//评估提醒（患者）
                YjhApplication.msg_evalution = false;
                YjhApplication.msg_system = false;//系统消息
                YjhApplication.msg_chat = false;//环信聊天
                YjhApplication.msg_new = false;//全部判断

                if (idChangeListener != null) {
                    idChangeListener.onDepartmentIdChange();
                }
                swipeRefreshLayout.setRefreshing(false);
                break;
            case MessageCode.NETWORKCODE_DEPARTMENTLEFT_FAILURE:
                swipeRefreshLayout.setRefreshing(false);
                if (msg.obj != null) {
                    toastMsg((String) msg.obj);
                } else {
                    toastMsg(R.string.departmentquitfail);
                }
                break;
            case MessageCode.NETWORKCODE_DEPARTMENTJOIN_SUCCESS:
                swipeRefreshLayout.setRefreshing(false);

                if (idChangeListener != null) {
                    idChangeListener.onDepartmentIdChange();
                }
                toastMsg(R.string.departmentjoinsuccess);
                loginInfo.setDepartmentId(departmentId);
                loginInfoDao.setUser(loginInfo);

                initData();
                break;
            case MessageCode.NETWORKCODE_DEPARTMENTJOIN_FAILURE:
                swipeRefreshLayout.setRefreshing(false);
                if (msg.obj != null) {
                    toastMsg((String) msg.obj);
                } else {
                    toastMsg(R.string.departmentjoinfail);
                }
                break;
            case MessageCode.NETWORKCODE_CONNECT_ERROR:
                swipeRefreshLayout.setRefreshing(false);
                break;
            //护士那块
            case MessageCode.NETWORKCODE_GETDEPARTMENTNURSELIST_SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                if (msg.obj != null) {
                    NurseWholeBean nurseWhole = (NurseWholeBean) msg.obj;
                    nurses.clear();
                    nurses.addAll(nurseWhole.getList());
                    initNurseInfo();
                } else {
                    toastMsg(R.string.departmentnursesgetfail);
                }
                break;
            case MessageCode.NETWORKCODE_GETDEPARTMENTNURSELIST_FAILURE:
                swipeRefreshLayout.setRefreshing(false);
                break;
            //新闻
            case MessageCode.NETWORKCODE_ARTICLELIST_SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                //  dismisssLoading();
                if (msg.obj != null) {
                    resultBean = (ArticleWholeBean) msg.obj;
                    if (resultBean.getList() != null) {

                        if (resultBean.getList().size() > 0) {
                            newsInfoList.clear();
                            newsInfoList.addAll(resultBean.getList());
                            // Log.e("数据", newsInfoList.get(0).toString());
                            informationAdapter.notifyDataSetChanged();

                        } else {

                        }
                    }
                }

                break;
            case MessageCode.NETWORKCODE_ARTICLELIST_FAILURE:
                swipeRefreshLayout.setRefreshing(false);
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }

                break;
            case MessageCode.BANNER_SUCCESS://banner成功
                swipeRefreshLayout.setRefreshing(false);
                if (msg.obj != null) {
                    BannerWholeBean bannerWholeBean = (BannerWholeBean) msg.obj;
                    if (bannerWholeBean.getList() != null) {
                        image_banner_empty.setVisibility(View.GONE);
                        imgelist.clear();
                        imgelist.addAll(bannerWholeBean.getList());
                        loadBanner();
                        // recycleViewpager.notifyDataSetChanged();
                        recycleViewpager.startAutoscrooll();
                    }
                    return;
                }
                break;
            case MessageCode.BANNER_FAILURE://banner失败
                swipeRefreshLayout.setRefreshing(false);
                break;

        }
    }

    //获取护士信息
    private void initNurseInfo() {
        if (nurses.size() > 0) {
            NurseBean nurseBean = nurses.get(0);
            //  Log.e("首页", nurseBean.toString());
            //责任护士
            if (nurseBean.getIsBinding().equals("0")) {
                line_nurse_empty.setVisibility(View.VISIBLE);
                responsibility_nurse_empty.setVisibility(View.GONE);
                text_advisory.setVisibility(View.VISIBLE);
                imageLoader.displayImage(nurseBean.getImg(), responsibility_nurse_icon, ImageOptionUtils.getInstance().getNurseHeadOptions());
                responsibility_nurse_name.setText(nurseBean.getName());
                nurse_work_office.setText(nurseBean.getTitle());
                if (TextUtils.isEmpty(nurseBean.getYear())) {
                    nurse_work_time.setText("从业<1年");
                } else {
                    long dateBegin = (new Date(Long.valueOf(nurseBean.getYear()))).getTime();
                    long dateNow = (new Date()).getTime();
                    long year = (dateNow - dateBegin) / 1000 / 60 / 60 / 24 / 365;
                    if (year >= 1) {
                        nurse_work_time.setText("从业" + (int) year + "年");
                    } else {
                        nurse_work_time.setText("从业<1年");
                    }
                }
            } else {
                text_advisory.setVisibility(View.GONE);
                line_nurse_empty.setVisibility(View.GONE);
                responsibility_nurse_empty.setVisibility(View.VISIBLE);
            }
        }

    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.user_frag_view, container, false);
        initView();
        initData();
        initListener();
        initPopup();
        loadInfo();
        return view;
    }

    @SuppressLint("WrongViewCast")
    @Override
    protected void initView() {

        iv_msgpoint = (ImageView) view.findViewById(R.id.iv_discover_point);
        image_banner_empty = (ImageView) view.findViewById(R.id.image_banner_empty);
        ll_empty = (LinearLayout) view.findViewById(R.id.ll_discover_empty);
        ll_ttitle = (LinearLayout) view.findViewById(R.id.ll_title);
        iv_qrcode = (ImageView) view.findViewById(R.id.iv_title_back);
        tv_title = (TextView) view.findViewById(R.id.tv_title_title);
        iv_tmessage = (ImageView) view.findViewById(R.id.iv_title_func);
        nodepartmentTV = (TextView) view.findViewById(R.id.no_department_display);
        nodepartmentTV.setText(R.string.join_us);
        msg_number = (TextView) view.findViewById(R.id.msg_home_number);
        //打开心电
        tv_openEcg = (TextView) view.findViewById(R.id.tv_open);
        ll_ecg = (LinearLayout) view.findViewById(R.id.ll_ecg);
        ll_ecg.setOnClickListener(this);
        tv_openEcg.setOnClickListener(this);

        iv_message = (ImageView) view.findViewById(R.id.iv_discover_message);


        iv_message.setOnClickListener(this);
        //更多
        ll_course = (LinearLayout) view.findViewById(R.id.ll_discover_course);

        //新闻
        ll_news = (LinearLayout) view.findViewById(R.id.ll_discover_news);
        //护士头像
        responsibility_nurse_icon = (CircleImageView) view.findViewById(R.id.responsibility_nurse_icon);
        //护士名字
        responsibility_nurse_name = (TextView) view.findViewById(R.id.responsibility_nurse_name);
        //工作时长
        nurse_work_time = (TextView) view.findViewById(R.id.nurse_work_time);
        //职位
        nurse_work_office = (TextView) view.findViewById(R.id.nurse_work_office);
        //咨询
        text_advisory = (TextView) view.findViewById(R.id.text_advisory);

        //资讯列表
        information_listView = (LinearListView) view.findViewById(R.id.information_listView);
        //责任护士不为空就显示出来
        line_nurse_empty = (LinearLayout) view.findViewById(R.id.line_nurse_empty);
        //责任护士为空的时候显示出来
        responsibility_nurse_empty = (TextView) view.findViewById(R.id.responsibility_nurse_empty);

        setTitlePadding(ll_ttitle);
        iv_qrcode.setImageResource(R.drawable.nav_scan);
        tv_title.setText(getResources().getString(R.string.homepage));
        iv_tmessage.setImageResource(R.drawable.nav_message);
        iv_qrcode.setVisibility(View.VISIBLE);
        iv_tmessage.setVisibility(View.VISIBLE);
        swipeRefreshLayout = (CustomSwipeToRefresh) view.findViewById(R.id.swiperefresh_discover);
        recycleViewpager = new InitRecycleViewpager();
        recycleViewpager.initView(getActivity(), view);

        recycleViewpager.setBannerHeight((int) (screenWidth * (408 / 750.0)));
        imgelist = new ArrayList<>();
      /*  imgelist.add("1");
        imgelist.add("2");
        imgelist.add("3");*/
        //院,前,中,后,随访
        line_yuan_qian = (LinearLayout) view.findViewById(R.id.line_yuan_qian);
        line_yuan_zhong = (LinearLayout) view.findViewById(R.id.line_yuan_zhong);
        line_yuan_hou = (LinearLayout) view.findViewById(R.id.line_yuan_hou);
        line_sui_fang = (LinearLayout) view.findViewById(R.id.line_sui_fang);
        newsInfoList = new ArrayList<>();
     /*   for (int i = 0; i < 6; i++) {
            ArticleBean newsInfo = new ArticleBean();
            newsInfoList.add(newsInfo);
        }*/
        informationAdapter = new InformationAdapter(newsInfoList, getActivity(), R.layout.information_item);
        information_listView.setDefaltWight();

        information_listView.setAdapter(informationAdapter);
        loginInfoDao = new LoginInfoDao(mContext);
        nurses = new ArrayList<>();
    }

    private void initPopup() {
        popup_easynotice = new PopupWindow(mContext);
        View viewNotice = LayoutInflater.from(mContext).inflate(R.layout.popup_easynotice, null);
        popup_easynotice.setContentView(viewNotice);

        popup_easynotice.setWidth((int) (screenWidth * 0.7));
        popup_easynotice.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        popup_easynotice.setFocusable(true);
        popup_easynotice.setTouchable(true);
        popup_easynotice.setOutsideTouchable(true);
        popup_easynotice.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popup_easynotice.setAnimationStyle(R.style.popupwindow_anim_alpha);

        tv_easynotice_title = (TextView) viewNotice.findViewById(R.id.tv_easynotice_title);
        tv_easynotice_cancel = (TextView) viewNotice.findViewById(R.id.tv_easynotice_cancel);
        tv_easynotice_sure = (TextView) viewNotice.findViewById(R.id.tv_easynotice_func);

        tv_easynotice_cancel.setOnClickListener(this);
        tv_easynotice_sure.setOnClickListener(this);

        tv_easynotice_title.setText(R.string.suretoquitdepartment);
        tv_easynotice_cancel.setText(R.string.cancel);
        tv_easynotice_sure.setText(R.string.sure);

        popup_easynotice.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                BrightnessUtils.lightOn(activity);
            }
        });
        if (showIcon) {
            iv_msgpoint.setVisibility(View.VISIBLE);
        } else {
            iv_msgpoint.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    protected void initListener() {

        swipeRefreshLayout.setEnabled(true);
        swipeRefreshLayout.setOnRefreshListener(this);
        swipeRefreshLayout.setProgressViewOffset(true, -20, 100);
        line_sui_fang.setOnClickListener(this);
        line_yuan_hou.setOnClickListener(this);
        line_yuan_qian.setOnClickListener(this);
        line_yuan_zhong.setOnClickListener(this);
        ll_course.setOnClickListener(this);
        text_advisory.setOnClickListener(this);
        iv_qrcode.setOnClickListener(this);
        iv_tmessage.setOnClickListener(this);
        information_listView.setOnItemClickListener(this);
        swipeRefreshLayout.setEnabled(false);
        // setTitlePadding(ll_title);
    }

    @Override
    protected void initData() {
        //loadBanner();
        //recycleViewpager.getInfinite_Pager().setOn
    }

    private void loadBanner() {

        recycleViewpager.initData(R.layout.viewpager_item, imgelist, new InitRecycleViewpager.BannerItemResponse() {
            @Override
            public void responseData(View convertView, int position) {
                // ImageView   image_dian= (ImageView) convertView.findViewById(R.id.image_dian);
                ImageView imageView_ads_icon = (ImageView) convertView.findViewById(R.id.imageView_ads_icon);
                imageView_ads_icon.setScaleType(ImageView.ScaleType.CENTER_CROP);
                ImageLoader.getInstance().displayImage(imgelist.get(position).getPicPath(), imageView_ads_icon,
                        ImageOptionUtils.getInstance().getWhitePicOptions());
                imageView_ads_icon.setTag(position);
                imageView_ads_icon.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int index = (int) v.getTag();
                        switch (v.getId()) {
                            case R.id.imageView_ads_icon:
                                // Log.e("点击-->",)
                                if (imgelist.get(index).getContentType().equals("1")) {
                                    Intent intent = new Intent(getActivity(), ArticleDetailActivity.class);
                                    intent.putExtra("articleId", imgelist.get(index).getContentPath());
                                    intent.putExtra("name", imgelist.get(index).getName());
                                    intent.putExtra("acctType", "1");
                                    intent.putExtra("kindTitle", imgelist.get(index).getName());
                                    startActivity(intent);
                                } else if (imgelist.get(index).getContentType().equals("2")) {
                                    Intent intent = new Intent(getActivity(), WebActivity.class);
                                    intent.putExtra("url", imgelist.get(index).getContentPath());
                                    intent.putExtra("title", imgelist.get(index).getName());
                                    startActivity(intent);
                                }
                                break;
                        }
                    }
                });
            }
        });
    }

    public void loadInfo() {
        swipeRefreshLayout.setEnabled(true);
        loading();
        YiJiaHuNetWorkUtils.getNurseList(loginInfo.getDepartmentId(), pageIndex, pageSize, handler);
        YiJiaHuNetWorkUtils.getDepartmentIndexInfo(loginInfo.getDepartmentId(), handler);
        // Log.e("测试-->",loginInfo.getDepartmentId());
        YiJiaHuNetWorkUtils.newarticleList(loginInfo.getDepartmentId(), "", "", "", 1, 6, handler);
        YiJiaHuNetWorkUtils.getBannerList(loginInfo.getDepartmentId(), handler);
    }

    @Override
    public void onPause() {
        super.onPause();
        if (recycleViewpager != null)
            recycleViewpager.stopAutoScroll();
    }

    @Override
    public void onResume() {
        super.onResume();
        if (TextUtils.isEmpty(loginInfo.getDepartmentId())) {
            ll_empty.setVisibility(View.VISIBLE);
        } else {
            if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                if (recycleViewpager != null)
                    recycleViewpager.startAutoscrooll();
                // loadInfo();
            }
            ll_empty.setVisibility(View.GONE);
        }

        YjhApplication.getInstance().showMsg(msg_number);


     /*   if (showIcon) {
            iv_msgpoint.setVisibility(View.VISIBLE);
        } else {
            iv_msgpoint.setVisibility(View.INVISIBLE);
        }*/
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (recycleViewpager != null)
            recycleViewpager.stopAutoScroll();
    }


    private UserDiscoverFragment.departmentIdChangeListener idChangeListener;

    public void setDepartmentIdChangeListener(UserDiscoverFragment.departmentIdChangeListener listener) {
        this.idChangeListener = listener;
    }

    public void setNewDepartment() {
    }

    public void showPoint(boolean show) {
        showIcon = show;
        if (iv_msgpoint == null)
            return;
        if (show) {
            iv_msgpoint.setVisibility(View.VISIBLE);
        } else {
            iv_msgpoint.setVisibility(View.INVISIBLE);
        }
        YjhApplication.getInstance().showMsg(msg_number);
    }

    @Override
    public void onRefresh() {
        // swipeRefreshLayout.setEnabled(false);
        loadInfo();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_discover_message:
                if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                    Intent iM = new Intent(mContext, MessageMainActivity.class);
                    startActivity(iM);
                } else {
                    toastMsg(R.string.pleasefirstjoindepartment);
                }
                break;
            case R.id.tv_open:
                mContext.startActivity(new Intent(mContext, AerotelActivity.class));
                break;
            case R.id.ll_ecg:
                //  跳转心电页面
                mContext.startActivity(new Intent(mContext, AerotelActivity.class));

                break;

            case R.id.tv_easynotice_func:
                popup_easynotice.dismiss();
                loading();
                YiJiaHuNetWorkUtils.departmentLeft(loginInfo.getUserId(), handler);
                break;
            case R.id.tv_easynotice_cancel:
                popup_easynotice.dismiss();
            case R.id.line_sui_fang://随访
                StringUtil.zhugeTrack(mContext, "随访图标区域", "统计课堂按钮点击数");
                Intent courseIntent4 = new Intent(getActivity(), NewNewsActivity.class);
                courseIntent4.putExtra("type", "4");
                startActivity(courseIntent4);
                break;
            case R.id.line_yuan_hou: //院后
                StringUtil.zhugeTrack(mContext, "院后图标区域", "统计课堂按钮点击数");
                Intent courseIntent3 = new Intent(getActivity(), NewNewsActivity.class);
                courseIntent3.putExtra("type", "3");
                startActivity(courseIntent3);
                break;
            case R.id.line_yuan_qian://院前
                StringUtil.zhugeTrack(mContext, "院前图标区域", "统计课堂按钮点击数");
                Intent newsIntent1 = new Intent(getActivity(), NewNewsActivity.class);
                newsIntent1.putExtra("type", "1");
                startActivity(newsIntent1);
                break;
            case R.id.line_yuan_zhong://院中
                StringUtil.zhugeTrack(mContext, "院中图标区域", "统计课堂按钮点击数");
                Intent newsIntent2 = new Intent(getActivity(), NewNewsActivity.class);
                newsIntent2.putExtra("type", "2");
                startActivity(newsIntent2);
                break;
            case R.id.ll_discover_course:

                break;
            case R.id.ll_discover_news:

                break;
            case R.id.text_advisory://咨询
                StringUtil.zhugeTrack(mContext, "责任护士区域中的咨询按钮", "统计咨询中发送信息按钮点击数");
                Intent iChat = new Intent(mContext, ChatFragmentActivity.class);
                iChat.putExtra(EaseConstant.EXTRA_USER_ID, "ejh" + nurses.get(0).getTel());
                String nursesName = nurses.get(0).getName();
                if (nursesName.length() > 8) {
                    nursesName = nursesName.substring(0, 8) + "...";
                }
                // nurses.get(0).getName().substring(0, 1) + "护士"
                iChat.putExtra("name", nursesName);
//                iChat.putExtra("easeuser","ejh"+nurses.get(position).getTel());
                startActivity(iChat);
                break;
            case R.id.iv_title_back:
                Intent iQR = new Intent(mContext, QRcodeScanActivity.class);
                startActivityForResult(iQR, REQUEST_QRCODE);
                break;
            case R.id.iv_title_func:
                if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                    Intent iM = new Intent(mContext, MessageMainActivity.class);
                    startActivity(iM);
                } else {
                    toastMsg(R.string.pleasefirstjoindepartment);
                }

        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == REQUEST_QRCODE) {
                departmentId = data.getStringExtra("result");

                if (!TextUtils.isEmpty(departmentId)) {
                    Intent iIntro = new Intent(mContext, JoinDepartmentActivity.class);
                    iIntro.putExtra("departmentId", departmentId);
                    startActivityForResult(iIntro, REQUEST_JOIN);

//                    loading();
//                    YiJiaHuNetWorkUtils.departmentJoin(departmentId, loginInfo.getUserId(), handler);
                }
            } else if (requestCode == REQUEST_JOIN) {
                boolean isJoin = data.getBooleanExtra("join", false);
                if (isJoin) {
//                    loading();
//                    YiJiaHuNetWorkUtils.departmentJoin(departmentId, loginInfo.getUserId(), handler);
                    if (idChangeListener != null) {
                        idChangeListener.onDepartmentIdChange();
                    }
                    loginInfo.setDepartmentId(departmentId);
                    loginInfoDao.setUser(loginInfo);
                    toastMsg(R.string.departmentjoinsuccess);
                    initData();
                } else {

                }
            }
        }
    }

    @Override
    public void onItemClick(LinearListView parent, View view, int position, long id) {
        StringUtil.zhugeTrack(mContext, "推荐文章全区域", "统计资讯点击数");
        ArticleBean article = newsInfoList.get(position);
        Intent intent = new Intent(getActivity(), ArticleDetailActivity.class);
        intent.putExtra("articleId", article.getArticleId());
        intent.putExtra("name", article.getName());
        intent.putExtra("acctType", "1");
        intent.putExtra("kindTitle", article.getKindName());
        startActivity(intent);
    }
}
